import 'package:environmental_les_app/common/routes/route_names.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';
import 'package:flutter_clx_base/widget/normal_dialog.dart';

import 'widgets/task_completed.dart';
import 'widgets/task_distribute.dart';
import 'widgets/task_supervision.dart';

class TaskDetailController extends GetxController {
  TaskDetailController();

  final Map<String, bool> expansionState = {
    'taskInfo': true,
    'clueInfo': true,
    'supervisionInfo': true,
    'processFlow': true,
  };

  bool isCluesExpanded = false;
  final allClues = [
    "线索 1",
    "线索 2",
    "线索 3",
    "线索 4",
    "线索 5",
    "线索 6",
    "线索 7",
    "线索 8",
    "线索 9",
    "线索 10",
    "线索 11"
  ];
  static const int _collapsedClueCount = 7;

  List<String> get cluesToShow =>
      isCluesExpanded ? allClues : allClues.take(_collapsedClueCount).toList();
  bool get canShowMoreClues => allClues.length > _collapsedClueCount;

  void toggleCluesExpansion() {
    isCluesExpanded = !isCluesExpanded;
    update(['task_detail']);
  }

  void toggleCard(String cardKey) {
    if (expansionState.containsKey(cardKey)) {
      expansionState[cardKey] = !expansionState[cardKey]!;
      update(["task_detail"]);
    }
  }

  _initData() {
    update(["task_detail"]);
  }

  void goToSupervision() {
    Get.bottomSheet(const TaskSupervision());
  }

  void goToComplete() {
    Get.bottomSheet(const TaskCompleted());
  }

  void goToDistribute() {
    Get.bottomSheet(const TaskDistribute());
  }

  void goToToMeHandle() {
    Get.toNamed(AppRoutes.taskFillingPage);
  }

  void goToSign() {
    Get.dialog(NormalDialog(
      title: "消息确认",
      content: "是否确认签收？",
      onConfirm: () {
        // 执行签收操作
        Get.back(); // 关闭对话框
        // 这里可以添加更多逻辑，比如刷新任务列表等
      },
    ));
  }

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
